from flask import Blueprint, request
import json

module_api = Blueprint('api', __name__, template_folder='templates')


@module_api.route('/press', methods=['GET'])
def press():
    from app.helper.press import get_press_shop_data
    from app.helper.press import read_json
    bind_type = request.args.get('type')
    result_database_value = get_press_shop_data(bind_type)
    result_input_value = read_json()
    return json.dumps(dict(result_database_value, **result_input_value))


@module_api.route('/press/input', methods=['POST'])
def press_input():
    from app.helper.press import write_json
    data_dict = request.form
    write_json(data_dict)
    result = {'code': 1}
    return json.dumps(result)
